package com.base.service.impl;

import java.util.List;

import com.base.bean.Personnelsales;
import com.base.service.PersonnelsalesService;
import com.common.util.AbstractManager;
import com.common.util.PagerModel;

public class PersonnelsalesServiceImpl extends AbstractManager implements
		PersonnelsalesService {

	public void addPersonnelsales(Personnelsales personnelsales) {
		String hql = "select nvl(max(personnelid),0) from Personnelsales";
		
		long personnelid = 0l;
		personnelid = (Long) this.getHibernateTemplate().find(hql).get(0);
		personnelid += 1l;
		
		personnelsales.setPersonnelid(personnelid);
		personnelsales.setPersonnelno(personnelid);
		this.getHibernateTemplate().save(personnelsales);
	}

	@SuppressWarnings("unchecked")
	public List<Personnelsales> findAllPersonnelsales() {
		String hql = "from Personnelsales order by personnelid";
		return this.getHibernateTemplate().find(hql);
	}

	public Personnelsales findPersonnelsales(long personnelid) {
		return (Personnelsales) this.getHibernateTemplate().load(Personnelsales.class, personnelid);
	}

	public PagerModel findPersonnelsalesForPager() {
		String hql = "from Personnelsales order by personnelid";
		return searchPaginated(hql);
	}

	public void removePersonnelsales(long personnelid) {
		Personnelsales personnelsales = null;
		personnelsales = (Personnelsales) this.getHibernateTemplate().load(Personnelsales.class, personnelid);
		if(personnelsales != null) 
			this.getHibernateTemplate().delete(personnelsales);
	}

	public void updatePersonnelsales(Personnelsales personnelsales) {
		this.getHibernateTemplate().update(personnelsales);
	}

}
